package 代码记录.剑指offer错题本;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @author zx
 * @create 2022-05-28 20:29
 */
public class Test1 {
    private static int res = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = sc.nextInt();
        }
        getSum(arr);
        System.out.println(res);
    }
    //求组合方案数
    private static void getSum(int[] arr){
        LinkedList<Integer> list = new LinkedList<>();
        helper(arr,0,list);
    }
    //回溯
    private static void helper(int[] arr,int startIndex,LinkedList<Integer> list){
        if(list.size() == 3){
            if(list.get(0) == list.get(2) && list.get(0) > list.get(1)){
                res++;
            }
        }
        for(int i = startIndex;i < arr.length;i++){
            list.add(arr[i]);
            helper(arr,i + 1,list);
            list.removeLast();
        }
    }
}
